package cn.ffcs.unm.position.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.stereotype.Repository;

import cn.ffcs.unm.position.dao.PositionDelDao;
import cn.ffcs.unm.position.model.PositionSequence;
import cn.ffcs.unm.position.model.PostBasicInformation;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("positionDelDao")
public class PositionDelDaoImpl extends BaseDaoImpl implements PositionDelDao {

	@Override
	public PageInfo queryPageInfoByPositionSequence(
			PositionSequence positionSequence, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from vie_OM_POSTSERIES v where 1=1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != positionSequence) {
			if (!StrUtil.isEmpty(positionSequence.getMonthId())) {
				sb.append(" AND v.monthId = ? ");
				params.add(positionSequence.getMonthId());
			}
			if (!StrUtil.isEmpty(positionSequence.getPostSeriesName())) {
				sb.append(" AND v.postseriesname LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(positionSequence
								.getPostSeriesName()) + "%");
			}
			if (!StrUtil.isEmpty(positionSequence.getPostSeriesCode())) {
				sb.append(" AND v.postseriescode LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(positionSequence
								.getPostSeriesCode()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, PositionSequence.class);
	}

	@Override
	public PageInfo queryPageInfoByPostBasicInformation(
			PostBasicInformation postBasicInformation, int currentPage,
			int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from vie_OM_POST v where 1=1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != postBasicInformation) {
			if (!StrUtil.isEmpty(postBasicInformation.getMonthId())) {
				sb.append(" AND v.monthId = ? ");
				params.add(postBasicInformation.getMonthId());
			}
			if (!StrUtil.isEmpty(postBasicInformation.getPostName())) {
				sb.append(" AND v.postname LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(postBasicInformation
								.getPostName()) + "%");
			}
			if (!StrUtil.isEmpty(postBasicInformation.getPostCode())) {
				sb.append(" AND v.postcode LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(postBasicInformation
								.getPostCode()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, PostBasicInformation.class);
	}

}
